home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c++,comp.lang.c,comp.os.ms-windows.programmer.misc
- Subject: Re: fastest code
- Date: Sat, 13 Apr 96 23:22:52 GMT
- Organization: none
- Message-ID: <829437772snz@genesis.demon.co.uk>
- References: <316112A2.7D37@public.sta.net.cn> <4kgu7g$n9a@solutions.solon.com> <4kh2p7INNkcq@keats.ugrad.cs.ubc.ca> <4kjdus$fiq@samba.rahul.net> <4kjpn0INN817@keats.ugrad.cs.ubc.ca> <829352535snz@genesis.demon.co.uk> <4kof6e$te@news1.mnsinc.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4kof6e$te@news1.mnsinc.com> huang@mnsinc.com "Szu-Wen Huang" writes:
-
- >Lawrence Kirby (fred@genesis.demon.co.uk) wrote:
-
- >: where the code for the latter certainly looks more efficient (although
- >: it is difficult to guess the exact instruction timings). I wonder if
- >: Watcom compiles the 2nd version correctly.
- >
- >Why do you say the latter looks more efficient?
-
- That's just the way the assembly generated looked. Since it is short here
- is the corresponding code for the loops with gcc, all other code is
- identical. Judge for yourself:
-
- for (i=0; i<16; i++)
- prom[i] = prom[i+i];
-
-
- leal -32(%ebp),%edx
- .align 4
- .L15
- movb (%edx),%al
- movb %al,-32(%ebx,%ebp)
- addl $2,%edx
- incl %ebx
- cmpl $15,%ebx
- jbe .L15
-
-
-
- for (i=0; i<16; i++)
- prom[i] = prom[2*i];
-
-
- .align 4
- .L15
- movb -32(%ebp,%ebx,2),%al
- movb %al,-32(%ebx,%ebp)
- incl %ebx
- cmpl $15,%ebx
- jbe .L15
-
- >A naive compiler would
- >perform an addition with the former and a multiplication with the latter.
-
- I try to avoid naive compilers.
-
- >One would almost always expect addition to be faster than multiplication.
- >An optimizing compiler might be able to realize they are actually the
- >same, and perhaps even decide to implement both as bitwise shifts.
-
- I expect most compilers can do this with optimisation turned off.
-
- >In any case, I wouldn't expect the former to be slower than the latter. (It
- >certainly *might* be, but chances are slim).
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-